<template>
	<view style="height: 80vh;">
		<!-- 滚动条 begin -->
		<mescroll-uni ref="mescrollRef" top="5px" :fixed="false" @init="mescrollInit" @down="downCallback" @up="upCallback">
			
			<!-- 列表部分 begin -->
			<view class="cu-card dynamic" v-for="(item,index) in list" :key="index">
				<view class="cu-item shadow" style="margin:15rpx 30rpx;">
					<view class="cu-list menu-avatar">
						<view class="cu-item">
							
							<view class="cu-avatar radius lg" :style="'background-image:url('+item.giftImg+');'"></view>
							
							<view class="content flex-sub">
								<view>名称:{{item.giftName}}</view>
								
								<view class="text-gray text-sm flex justify-between">
									申请时间:{{GetDateDiff(item.createdAt)}}
								</view>
							</view>
							<view class="action text-red text-bold" style="width:150rpx;" v-if="item.statusEvaluation!=21&&item.statusEvaluation!=12">									
								{{item.orderStatusText}}
							</view>
							<view class="action text-red text-bold" style="width:150rpx;" v-else>
								{{item.statusEvaluationText}}
							</view>
						</view>
					</view>
					
					<view class="text-gray text-sm text-right padding-sm solid-top">							
						<view>
							<button class="cu-btn radius sm bg-grey margin-left" @tap="navigateTo({url:'/pages/order/old_detail?orderSn='+item.orderSn+'&type='+(isSell?1:2)})">取消申请</button>
							<button class="cu-btn radius sm bg-red margin-left" @tap="goDetail(item)">申请详情</button>
						</view>
					</view>
				</view>
			</view>
			<!-- 列表部分 end -->
			
		</mescroll-uni>
		<!-- 滚动条 end -->
		
		<!-- 个人详情窗口 begin -->
		<userDetailWin :showModel="showUserDetailModel" :userId="userId"  @closeWin="closeUserDetailWin"  />
		<!-- 个人详情窗口 end -->
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import * as confirm from '@/common/confirm.js'
	import {getDateDiff,getDateDiffMinute} from '@/utils/date/date.js';
	import {mapGetters} from 'vuex'
	import userDetailWin from "@/components/user-detail-win/user-detail-win"
	import imgList from '@/components/img-list/img-list.vue'
	
	export default {
		mixins: [MescrollMixin],
		components:{
				userDetailWin,
				imgList
		}, 
		data() {
			return {
				list:[],
				status:0,
				userId:-1,
				typeStr:"卖家",
				showUserDetailModel:false,
			};
		},
		name: 'scroll-other-order',
		props: {
			url: {
				type: String,
				default: ''
			},
			detailUrl: {
				type: String,
				default: ''
			},
			orderType:{
				type:String,
				default:''
			},
			refresh:{
				type:Boolean,
				default:false
			}
		},
		//页面创建方法,相当于onload
		watch:{
			refresh(val){
				if(val){
					this.mescroll.resetUpScroll(false);
					this.$emit("isrefresh")
				}
			}
		},
		created() {
			if(this.orderType!=5){
				this.status=this.orderType
			}else{
				this.status=undefined
			}
		},
		methods: {
			//数据操作类-------------------------
			upCallback(page) {
				let _this=this
				let pageNum = page.num; // 页码, 默认从1开始
				let pageSize = page.size; // 页长, 默认每页10条
				
				console.log(_this.orderType)
				
				var data={
					"p":pageNum,
					"s":pageSize,
				}
				if(this.status!=undefined){
					data.t=this.status
				}
				
				_this.$api.post(this.url,data).then(res => {	
					if (res.status == 200){
						
						let data=res.data
						let list=data.data
						
						let curPageLen=list.length
						let totalSize=data.count
						
						if(page.num == 1) this.list = [];
						
						_this.list = _this.list.concat(list)
												
						_this.mescroll.endBySize(curPageLen, totalSize);					
						setTimeout(()=>{
							_this.mescroll.endSuccess(curPageLen)
						},20)
					}else{
						uni.showToast({
							icon: 'none',
							title: '网络异常'
						})
					}
					
				}).catch(error=>{
					console.log(error)
					uni.showToast({
						icon: 'none',
						title: '网络异常'
					})
				})
			},			
			//取得时间间隔
			GetDateDiff:function(e){
				return getDateDiff(e)
			},
			showUserDetail(userId){
				this.userId=userId
				this.showUserDetailModel=true
			},
			closeUserDetailWin(){
				this.showUserDetailModel=false
			},
			goDetail(item){				
				uni.navigateTo({url:'/pages/order/my_order_detail?orderSn='+item.orderSn+'&type=1'})
			},
			remove(id){
				confirm.choose('确认删除订单?',(id)=>{						
					let url='/seller/order/del'
					if(!this.isSell){
						url='/buyer/order/del'
					}						
					this.$api.post(url,{id:id}).then(res => {
						if(res.code==200){
							this.mescroll.resetUpScroll(false);
						}else{
							confirm.error("删除订单出错!!")
						}
					})
				},id)
			},
		}
	};
</script>